﻿using System;
using System.Windows.Forms;
using ICRprojekt.Baza;

namespace ICRprojekt
{
    public partial class IspisHighscore : Form
    {
        /// <summary>
        /// Konstruktor.
        /// </summary>
        public IspisHighscore(int noviBodovi )
        {
            InitializeComponent ( );
            if (noviBodovi!=-1)
            {
                txt_bod.Text = noviBodovi.ToString();
                txt_bod.Visible = true;
                txt_unos.Visible = true;
                btn_SaljiRezultat.Visible = true;
            }
            else
            {
                txt_bod.Visible = false;
                txt_unos.Visible = false;
                btn_SaljiRezultat.Visible = false;

                // KOD ZA TESTIRANJE
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Lokas", 20000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Rukavina", 18000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Bešlagić", 16000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Rodik", 14000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Rašica", 12000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Klemen", 10000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Tironi", 8000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Rodik", 6000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Klemen", 4000));
                //BazaCentar.Bodovi_Insert(new HighScoreItem("Rukavina", 2000));
                Ispis_Rezultata(10);
            }
        }

        /// <summary>
        /// Prilikom loadanja ispisuje sve rezultate.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IspisHighscore_Load( object sender, EventArgs e )
        {

        }

        private void menuItem1_Click( object sender, EventArgs e )
        {
            Close( );
        }

        //private void btn_SaljiOdgovor_Click(object sender, EventArgs e)
        //{

        //}

        private void btn_SaljiRezultat_Click(object sender, EventArgs e)
        {
            BazaCentar.Bodovi_Insert(new HighScoreItem(txt_unos.Text,Convert.ToInt32(txt_bod.Text)));
            txt_bod.Visible = false;
            txt_unos.Visible = false;
            btn_SaljiRezultat.Visible = false;
            Ispis_Rezultata(10);
        }

        private void Ispis_Rezultata(int broj)
        {
            var lista = BazaCentar.Bodovi_Select(broj);
            foreach (var item in lista)
            {
                txt_imena.Text += (item.Name) + Environment.NewLine;
                txt_bodovi.Text += (item.Score) + Environment.NewLine;
            }
        }
    }
}